"""
pip install outetts
huggingface: https://huggingface.co/OuteAI/Llama-OuteTTS-1.0-1B
github:  https://github.com/edwko/OuteTTS
支持人声特征采样，合成与原说话者类似的口音。
"""
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"

import outetts

# Initialize the interface
interface = outetts.Interface(
    config=outetts.ModelConfig.auto_config(
        model=outetts.Models.VERSION_1_0_SIZE_1B,
        # For llama.cpp backend
        backend=outetts.Backend.LLAMACPP,
        quantization=outetts.LlamaCppQuantization.FP16
        # For transformers backend
        # backend=outetts.Backend.HF,
    )
)

# # Load the default speaker profile
# speaker = interface.load_default_speaker("EN-FEMALE-1-NEUTRAL")

# Or create your own speaker profiles in seconds and reuse them instantly
speaker = interface.create_speaker("/root/TransVoice/datas/speech/03882d1404db053486a68112d40b5da3e58e6454.wav")
# interface.save_speaker(speaker, "speaker.json")
# speaker = interface.load_speaker("speaker.json")

texts = [
    'hello, world',
    '我表舅妈，一个长在红旗下，满脑袋正能量的北京老太太，自从偶然看到小红书上的一些言论后，都不敢对我表弟催婚了。',
    'ເຄື່ອງຄິດເລກຂອງນັກການເມືອງອາເມຣິກາແມ່ນຄິດໄລ່ “ພາສີລັກສະນະເທົ່າທຽມກັນ” ອອກມາແບບແນວໃດ?',
    'บนอินเทอร์เน็ตมีแค่ 70 กว่าบรรทัดเท่านั้นใช่ไหม',
    'Apa yang anda katakan mungkin tidak pernah berlaku. ',
    'Tinh Chất Dưỡng Sáng Da Cô Đặc Bottega Verde'
]
# Generate speech
for idx, text in enumerate(texts):
    output = interface.generate(
        config=outetts.GenerationConfig(
            text=text,
            # text="Hello, how are you doing today? I hope you're having a wonderful day!",
            generation_type=outetts.GenerationType.CHUNKED,
            speaker=speaker,
            sampler_config=outetts.SamplerConfig(
                temperature=0.4
            ),
        )
    )
    output.save(f"./output{idx}.wav")